﻿@model IEnumerable<Category>
@{
    ViewBag.Title = "分类管理";
}
<a asp-action="Edit" class="btn btn-primary mb-3"><i class="fa fa-plus"></i> 新增分类</a>
<table class="table table-hover">
    <thead class="thead-light">
        <tr>
            <th>编号</th>
            <th>名称</th>
            <th>排序</th>
            <th>文章数</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
    {
        <tr>
            <td>@item.Id</td>
            <td>@item.Name</td>
            <td>@item.OrderNo</td>
            <td>@item.Articles.Count 篇</td>
            <td>
                <a asp-action="Edit" asp-route-id="@item.Id"><i class="fa fa-edit"></i> 编辑</a>
                @if (!item.IsSystem)
            {
                <a href="javascript:remove('@item.Id');" ><i class="fa fa-trash"></i> 删除</a>
        }
            </td>
        </tr>
}
    </tbody>
</table>
@section scripts{ 
    <script type="text/javascript">
        function remove (id){            
            if (confirm('确定删除吗？')) {
                $.ajax({
                    url: '@Url.Action("Delete")',
                    method: 'post',
                    data: { id: id },
                    success: function () {
                        location.reload();
                    },
                    error: function (data) {
                        alert(data.responseText);
                    }
                });
            }
        }
    </script>
}